#pragma once

#include<stdlib.h>
#include<stdio.h>

#define LIST_INIT_SIZE 100
#define LIST_INCREMENT 10
#define SUCCESS 0
#define FAILURE 1
#define TRUE 1
#define FALSE 0
#define ERROR -1

#define MORE 1
#define EQUAL 0
#define LESS -1

typedef int Status;

// 定义一个简单的线性表

#define ElemType int
typedef struct LinerList{
    ElemType *elem;
    unsigned int length;
    unsigned int listSize;
}SqList;

// elem1 > elem2  return 1
// elem1 == elem2 return 0
// elem1 < elem2  return -1
Status CompareElemType(ElemType elem1, ElemType elem2)
{
    if (elem1 > elem2) {
        return MORE;
    } else if (elem1 == elem2) {
        return EQUAL;
    } else {
        return LESS;
    }
}

/* 结构初始化 构建一个空链表 */
Status InitList(SqList *sqList);

/* 销毁结构 */
void DestoryList(SqList *sqList);

/* 引用型操作 （不对线性表结构更改）*/
// 判空操作
Status ListEmpty(SqList sqList);

// 线性表当前长度
unsigned ListLength(SqList sqList);

// 线性表当前元素的前驱
Status PiiorElem(SqList sqList, ElemType curElem, ElemType *preElem);

// 当前元素的后继
NextElem(SqList sqList,ElemType curElem, ElemType &nextElem);

// 获取线性表 中第i个元素
Status GetElemFormPosition(SqList sqList,unsigned int position, ElemType *elem);

// 获取线性表中给定元素的位置
Status GetElemPosition(SqList sqList, ElemType elem, unsigned int *u4Position);

// 获取满足compare关系的第一个元素的位序
LocateElem(SqList sqList, ElemType &elem, compare());

// 依次对线性表的每个元素调用visit()
ListTraverse(SqList sqList, visit());

/* 加工型操作 （更改线性表的结构）*/
// 清空线性表（置为空表）
ClearList(SqList &sqList);

// 更改线性表中第i个位置的元素
SetElem(SqList sqList,unsigned int position, ElemType elem);

// 插入操作
ListInsert(SqList &sqList,unsigned int position, ElemType &elem)

// 删除操作
ListDelete(SqList &sqList, unsigned int position, ElemType &elem);


// 算法2.1

// 算法 2.2

// 算法 2.3

